package com.mjee.app.service.support;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mjee.app.domain.User;
import com.mjee.app.domain.UserDetail;
import com.mjee.app.mapper.UserMapper;
import com.mjee.app.service.AbstractService;
import com.mjee.app.service.UserService;
import com.mtoolkit.page.Page;

/**
 * User service support.
 * 
 * @author michael
 * @version $Id: UserServiceImpl.java, v 0.1 2012-9-26 下午1:29:40 michael Exp $
 */
@Service
public class UserServiceSupport extends AbstractService<User> implements UserService  {
	
    @Autowired
    public UserServiceSupport(UserMapper userMapper) {
		super(userMapper);
	}
    
    @Override
    public User findUser(String userName) {
        return userMapper.selectByName(userName);
    }

    public User findUserDetail(int id) {
    	User targetUser = userMapper.select(id);

    	if (targetUser != null) {
    		UserDetail userDetail = userDetailMapper.selectByUserId(id);
    		targetUser.setUserDetail(userDetail);
    	}
    	
    	return targetUser;
    }
    
    @Override
    public Page<User> queryUsers(Page<User> page) {
        List<User> userList = userMapper.selectByPage(page, null);
        page.setResultList(userList);
        
        return page;
    }
    
}